import random
import time


def chuti(seq_operand, num=10, maxValue=10):
    real_operand = {0: '+', 1: '-', 2: '*', 3: '/'}
    real_answer = []
    seq = []
    for i in list(range(0, num)):
        if seq_operand[i] == 3:
            strQuest = f'{random.randint(0, maxValue)}{real_operand[seq_operand[i]]}{random.randint(1, maxValue)}'
        else:
            strQuest = f'{random.randint(0, maxValue)}{real_operand[seq_operand[i]]}{random.randint(0, maxValue)}'
        while eval(strQuest) >= maxValue:
            if seq_operand[i] == 3:
                strQuest = f'{random.randint(0, maxValue)}{real_operand[seq_operand[i]]}{random.randint(1, maxValue)}'
            else:
                strQuest = f'{random.randint(0, maxValue)}{real_operand[seq_operand[i]]}{random.randint(0, maxValue)}'
        real_answer.append(float(eval(strQuest)))
        seq.append(strQuest + '=')
    return seq, real_answer


def operand(num=10):
    count = 0
    seq2 = []
    while set(seq2) != {0, 1, 2, 3}:
        seq2 = []
        for i in range(0, num):
            seq2.append(random.randint(0, 3))
            while i > 0 and seq2[i - 1] == seq2[i]:
                seq2[i] = random.randint(0, 3)
    return seq2


def check(myAnswer, realAnswer):
    fault = []
    if myAnswer == realAnswer:
        print('满分')
        return fault
    else:
        fault = [i for i in range(0, len(realAnswer) - 1) if myAnswer[i] != realAnswer[i]]
        print('你的分数是%d' % (len(realAnswer) - len(fault)))
        print('总分是:%d' % (len(realValue) * 10))
        return fault
    

if __name__ == '__main__':
    myValue = []
    difficulty = int(input('请输入难度，10、100、1000：'))
    num = int(input('请输入题目数量(至少4道题)：'))
    question, realValue = chuti(operand(num), num=num, maxValue=difficulty)
    time_start = time.time()
    for order, quest in enumerate(question):
        myValue.append(float(input(f'第{order + 1}题：\t{quest}')))
        print()
    time_end = time.time()
    print('答题总用时：%.2f S' % (time_end - time_start))
    for i in check(myValue, realValue):
        print(f'第{i}题出错,正确的答案是：{question[i]}={realValue[i]}')
